// def
package util

import (
	"bytes"
	"encoding/binary"
)

//2字节解码为uint16
func Uint16Decode(high, low byte) uint16 {
	v := uint16(high)<<8 | uint16(low)
	return v
}

//2字节解码为int16
func Int16Decode(high, low byte) int16 {
	var v int16
	br := bytes.NewReader([]byte{high, low})
	binary.Read(br, binary.BigEndian, &v)
	return v
}

//返回b的pos位的值，0或1
func BitDecode(b byte, pos int) byte {
	if pos > 0 {
		b = b >> byte(pos)
	}
	v := b & 0x01
	return v
}
